package com.cn.law.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cn.law.pojo.Lawyer;

import com.cn.law.pojo.User;
import com.cn.law.service.LawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.UUID;

@CrossOrigin
@RestController
@RequestMapping("/lawyer")

public class LawyerController {
    @Autowired
    private LawyerService lawyerService;

    @RequestMapping("/findAllLawyer")
    public List<Lawyer> findALLLawyer() {
        return lawyerService.findAllLawyer();
    }

    @RequestMapping("/addLawyer")
    public boolean addLawyer(@RequestBody String lawyerstring) {
        System.out.println(lawyerstring);
        JSONObject lawyerjson = JSON.parseObject(JSON.parseObject(lawyerstring).get("user").toString());
        Lawyer lawyer = JSON.parseObject(lawyerjson.toString(), Lawyer.class);
        lawyer.setId(UUID.randomUUID().toString());
        System.out.println(lawyer.toString());
        return lawyerService.addLawyer(lawyer);
    }

    @RequestMapping("/deleteLawyerById")
    public boolean deleteLawyerById(String id) {
        return lawyerService.deleteLawyerById(id);
    }

    @RequestMapping("/loginLawyer")  //登录
    public Lawyer loginLawyer(String lawyer_username, String lawyer_password) {
        return lawyerService.loginLawyer(lawyer_username, lawyer_password);
    }

    @RequestMapping("/updateLawyer") //修改
    public boolean updateLawyer(@RequestBody Lawyer lawyer) {
        return lawyerService.updateLawyer(lawyer);
    }

}
